import { Component, OnInit, ElementRef } from '@angular/core';
import { TreeNode } from 'primeng/primeng';
import { RoleControlService } from './role-control.service';
import { FormsModule, Validators, FormGroup, FormControl } from '@angular/forms';
import * as _ from 'lodash';
import { AppPaginationComponent, PaginationModel } from "../../../widgets/pagination/pagination.component";
import { environment } from '../../../../environments/environment';
import 'ztree';
@Component({
  selector: 'app-role-control',
  templateUrl: './role-control.component.html',
  styleUrls: ['./role-control.component.scss'],
  providers: [RoleControlService]
})

export class RoleControlComponent implements OnInit {
  //下拉框部门信息
  public deptList = [];
  //按钮展示列表
  public menuResourceList = [];
  //初始化组织树post数据
  public initializationPostInfo = [];
  //添加用户post数据
  public addUserPost = [];
  //组织树配置
  deptTreeSetting = {
    data: {
      simpleData: {
        enable: true,
        idKey: "data",
        pIdKey: "pId"

      },
      key: {
        name: "label"
      }
    },
    callback: {
      onClick: (event, treeId, treeNode) => {
        if (treeNode.users) {
          this.staffList = treeNode.users;
          this.ctrlCheckAll(treeNode.users, 'deptCheckAll');
        }
        console.log(treeNode)
      }
    }
  };
  //角色组织树
  public deptTreeNodes = [];
  //菜单权限树配置
  menuTreeSetting = {
    data: {
      simpleData: {
        enable: true,
        idKey: "data",
        pIdKey: "pId"

      },
      key: {
        name: "label"
      }
    },
    check: {
      enable: true,
      chkStyle: "checkbox",
      chkboxType: { "Y": "ps", "N": "ps" }
    },
    callback: {
      onCheck: (event, treeId, treeNode) => {
      },
      onClick: (event, treeId, treeNode) => {
        if (treeNode.resource !== null) {
          this.menuResourceList = treeNode.resource;
          this.ctrlCheckAll(treeNode.resource, 'menuCheckAll');
        } else {
          this.menuResourceList = [];
          this.ctrlCheckAll(treeNode.resource, 'menuCheckAll');
        }

      }
    },


  };
  //角色菜单树
  public menuTreeNodes = [];
  //测试select2
  public fundSelectedCodeList = [];

  //删除角色用户(单个)put数据
  public delUserputBody = {
    sUsername: '',
    nRoleid: ''
  };
  // 组织树列表是否全选
  public isCheckedAll = false;
  //数据权限产品分类全选
  public isCheckedAll1 = false;
  //文档权限产品分类全选
  public isCheckedDocumentPublic = false;
  public isCheckedDocumentOtm = false;
  public isCheckedDocumentOto = false;
  public isCheckedDocumentAnnuity = false;
  public isCheckedDocumentOldage = false;
  public isCheckedDocumentOldagePro = false;
  public isCheckedDocumentSocial = false;
  //菜单按钮全选
  public isCheckedAll3 = false;
  public aloneList = [];
  public sMenuCode: any;
  //定义编辑或者添加的变量
  public addOrEditRoleBody: any = {
    nRoleid: "",
    sRolename: '',
    sRoletype: '',
    sDeptcode: '',
    sOperator: ''
  }

  //添加用户到角色时所需要获取的角色id
  public roleId: any;
  //判断模态框为编辑或者新增
  public isEditOrAddModal = '';
  // 角色列表数据
  public roleList: any;
  //角色用户列表
  public roleUserList = [];
  //部门员工list
  public staffList = [];


  //菜单权限--判断是否重复点击同一子菜单
  public isRepeatCheck = [];

  // public repeatCheckMenuId = [];
  //查询角色分页列表post数据
  public roleListPost = {
    pageIndex: 1,
    pageSize: environment.pageSize,
    sRolename: ""
  };
  /**
  * 角色列表管理分页
  */
  public roleListPageInfo: PaginationModel = {
    currentPageNum: 1,
    pageSize: 10,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };
  public listCount = 10;
  public system: any = {
    name: "",
    describe: "",
    depart: "",
    type: ""

  };
  //更新数据权限put数据
  public roleDataPutBody = {
    nRoleid: Number,
    sFundtypeSet: '',
    sFundcodes: '',
    sAttachSet: ''
  };
  //查询用户代码post
  public getListRoleDataFundCodePagePost = {
    pageIndex: 0,
    pageSize: 0
  };
  //数据权限产品类型
  public dataAuthorityList: any = [];
  //判断是否已加载产品类型接口
  public isLoadingFundType:any = false;
  //数据权限基金代码
  public fundCodeList:any = [];
  //数据权限选中的基金代码
  public fundCodeCheckedList = [];
  //数据权限文档类型
  public documentAuthorityPublicList = [];
  public documentAuthorityPublicLableName: any;
  public documentAuthorityOtmList = [];
  public documentAuthorityOtmLableName: any;
  public documentAuthorityOtoList = [];
  public documentAuthorityOtoLableName: any;
  public documentAuthorityAnnuityList = [];
  public documentAuthorityAnnuityLableName: any;
  public documentAuthorityOldageList = [];
  public documentAuthorityOldageLableName: any;
  public documentAuthorityOldageProList = [];
  public documentAuthorityOldageProLableName: any;
  public documentAuthoritySocialList = [];
  public documentAuthoritySocialLableName: any;
  // 角色新增或编辑信息
  public roleAddOrEditInfo: any = {
    nRoleid: ""
  };
  public label: any;
  //角色菜单资源权限标签list
  public menuResLabelList = [];

  //角色菜单资源权限标签隐式list
  public menuResLabelHideList = [];
  constructor(public roleControlService: RoleControlService, public el: ElementRef) { }

  ngOnInit() {
    let that = this;
    window['$'](".select2").select2();
    this.getRoleList();

    //  实例化角色管理select2
    window['$']('.sDeptcode').select2({
      width: '180px',
      // minimumResultsForSearch: 0
    });
    //  把所属部门所选的值赋给对应数据
    window['$']('.sDeptcode').on("select2:select", function (e) {
      that.roleAddOrEditInfo.sDeptcode = window['$']('.sDeptcode').select2("val")
    });

  }
  /**
   * 列表全选
   * @param status
   */
  checkedAll(data, checkAllId) {

    if (checkAllId) { // 更新为全选
      _.forEach(data, item => {
        item.checked = true;
      });
    } else { // 更新为不全选
      _.forEach(data, item => {
        item.checked = false;
      });
    }
  }
  // 列表是否全选
  ctrlCheckAll(data, checkAllBtn) {
    let that = this;
    let checkList = [];
    if (data !== null) {
      _.forEach(data, item => {
        if (item.checked == true) {
          checkList.push(item);
        }
      });
      if (checkList.length == data.length && checkList.length != 0) {
        switch (checkAllBtn) {
          case 'menuCheckAll':
            that.isCheckedAll3 = true;
            break;
          case 'deptCheckAll':
            that.isCheckedAll = true;
            break;
          case 'fundTypeCheckAll':
            that.isCheckedAll1 = true;
            break;
          case 'documentPublicCheckAll':
            that.isCheckedDocumentPublic = true;
            break;
          case 'documentOtmCheckAll':
            that.isCheckedDocumentOtm = true;
            break;
          case 'documentOtoCheckAll':
            that.isCheckedDocumentOto = true;
            break;
          case 'documentAnnuityCheckAll':
            that.isCheckedDocumentAnnuity = true;
            break;
          case 'documentOldageCheckAll':
            that.isCheckedDocumentOldage = true;
            break;
          case 'documentOldageProCheckAll':
            that.isCheckedDocumentOldagePro = true;
            break;
          case 'documentSocialCheckAll':
            that.isCheckedDocumentSocial = true;
            break;
        }
      } else {
        switch (checkAllBtn) {
          case 'menuCheckAll':
            that.isCheckedAll3 = false;
            break;
          case 'deptCheckAll':
            that.isCheckedAll = false;
            break;
          case 'fundTypeCheckAll':
            that.isCheckedAll1 = false;
            break;
          case 'documentPublicCheckAll':
            that.isCheckedDocumentPublic = false;
            break;
          case 'documentOtmCheckAll':
            that.isCheckedDocumentOtm = false;
            break;
          case 'documentOtoCheckAll':
            that.isCheckedDocumentOto = false;
            break;
          case 'documentAnnuityCheckAll':
            that.isCheckedDocumentAnnuity = false;
            break;
          case 'documentOldageCheckAll':
            that.isCheckedDocumentOldage = false;
            break;
          case 'documentOldageProCheckAll':
            that.isCheckedDocumentOldagePro = false;
            break;
          case 'documentSocialCheckAll':
            that.isCheckedDocumentSocial = false;
            break;
        }
      }
    }
  }
  //角色列表管理分页
  public rolePageNavigation(currentPageNum: number) {
    this.roleListPageInfo.currentPageNum = currentPageNum;
    this.getRoleList(this.roleListPageInfo.currentPageNum,
      this.roleListPageInfo.pageSize)
  }
  /**
* 改变字典列表显示记录数
* @param {pageSize}
*/
  public rolepageSizeChange(pageSize: number) {
    if (pageSize !== this.roleListPageInfo.pageSize) {
      this.roleListPageInfo.pageSize = pageSize;
      // this.bondsManpageInfo.currentPageNum = 1;
      this.getRoleList();
    }
  }
  /**
   * 点击打开用户管理modal
   */
  showRoleControlInfo(type?, item?) {


    let that = this;
    //显示下拉框部门信息
    this.getAlldept();
    if (item) {
      this.roleAddOrEditInfo.nRoleid = item.nRoleid;
      this.roleAddOrEditInfo.sRolename = item.sRolename;
      this.roleAddOrEditInfo.sDeptcode = item.sDeptcode;
      this.roleAddOrEditInfo.sDesc = item.sDesc;
      this.roleId = item.nRoleid;
    }
    switch (type) {
      case 'add':
        that.isEditOrAddModal = 'add';
        that.roleAddOrEditInfo.nRoleid = "";
        that.roleAddOrEditInfo.sRolename = '';
        that.roleAddOrEditInfo.sRoletype = '';
        that.roleAddOrEditInfo.sDeptcode = '';
        that.roleAddOrEditInfo.sDesc = '';
        that.roleUserList = [];
        that.roleId = undefined;
        break;
      case 'edit':
        that.isEditOrAddModal = 'edit';
        that.roleAddOrEditInfo.nRoleid = item.nRoleid;
        that.sMenuCode = '';
        that.getMenuTree();
        that.fundSelectedCodeList = [];
        that.dataAuthorityList = [];
        // that.getDataAuthority();
        that.getDocumentAuthority();
        that.getRoleUserList();
        break;
    }
    window['$']("#add-role-user").modal('hide');
    window['$']("#role-control-info").modal();
  }
  /**
   * 点击关闭角色添加用户modal，清空staffList
   */
  hideUserModal() {

    window['$']("#add-role-user").modal('hide');
    window['$']("#role-control-info").modal();
    
    // this.staffList = [];
  }
  /**
   * 点击打开添加用户modal
   */
  showAddUser() {
    if (this.isEditOrAddModal == 'edit' || this.roleId !== undefined) {
      this.getDeptTree();
      window['$']("#role-control-info").modal('hide');
      window['$']("#add-role-user").modal();
    } else {
      window['swal']("提示", "请先保存角色,再添加用户", "warning");
    }


  }

  //获取菜单权限树
  getMenuTree() {
    let that = this;
    var updateMenuTreePost = [];
    this.menuResourceList = [];
    this.roleControlService.getMenuTree(this.roleId).subscribe(data => {
      if (data) {
        console.log(data)
        this.menuTreeNodes = data.children;
        window['$'].fn.zTree.init(window['$']("#menuZtree"), this.menuTreeSetting, this.menuTreeNodes);
      }
    });
  }
  //获取组织树
  getDeptTree() {
    let that = this;
    this.staffList = [];
    this.roleControlService.getDeptTree(this.roleId).subscribe(data => {
      if (data) {
        this.deptTreeNodes = data.children;
        window['$'].fn.zTree.init(window['$']("#deptZtree"), this.deptTreeSetting, this.deptTreeNodes);
        this.initializationPostInfo = this.needPostBody();
      }
    });
  }
  /**
   * 角色管理分页列表
   */
  getRoleList(pageNum?, pageSize?) {
    let that = this;
    this.roleListPost.sRolename = _.trim(this.roleListPost.sRolename);
    this.roleListPost.pageIndex = pageNum ? pageNum : this.roleListPageInfo.currentPageNum;
    this.roleListPost.pageSize = pageSize ? pageSize : this.roleListPageInfo.pageSize;
    this.roleControlService.getRoleList(this.roleListPost).subscribe(data => {
      if (data) {
        that.roleList = data.list;
        that.roleListPageInfo.currentPageNum = data.pageNum;
        that.roleListPageInfo.totalPages = data.pages;
        that.roleListPageInfo.total = data.total; // 总记录数
        that.roleListPageInfo.startRow = data.startRow;
        that.roleListPageInfo.endRow = data.endRow;
      }
    })
  }
  // 角色新增或编辑
  addOrEditRole() {
    let that = this;
    if (this.requireAdd()) {
      window['swal']({
        title: "提示",
        text: "是否确定保存角色信息?",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "确认",
        confirmButtonColor: "#DD6B55",
        cancelButtonText: "取消",
        showLoaderOnConfirm: true,
      }, function (isConfirm) {
        if (isConfirm) {
          if (that.isEditOrAddModal == 'add' && that.roleAddOrEditInfo.nRoleid == "") {
            that.roleControlService.addRole(that.roleAddOrEditInfo).subscribe(data => {
              if (data) {
                window['swal']("成功", "添加成功!", "success");
                that.roleId = data.nRoleid;
                that.roleAddOrEditInfo.nRoleid = data.nRoleid;
                that.getRoleList();
                that.tabActive();
              }
            })
          } else if (that.isEditOrAddModal == 'edit' || that.roleAddOrEditInfo.nRoleid !== "") {
            that.roleControlService.editRole(that.roleAddOrEditInfo).subscribe(data => {
              if (data) {
                window['swal']("成功", "保存成功!", "success");
                // window['$']("#role-control-info").modal('hide');
                that.roleAddOrEditInfo.nRoleid = data.nRoleid;
                that.getRoleList();
                that.tabActive();
              }
            })
          }
        }
      })
    }
  }
  // 新增、编辑必填校验
  requireAdd() {
    let that = this;
    let sRolename = _.trim(this.roleAddOrEditInfo.sRolename);
    if (sRolename == "" || sRolename == null) {
      window['swal']("提示", "角色名称不能为空", "warning");
      return false;
    } else {
      return true;
    }
  }
  // 删除角色
  delRole(item) {
    let that = this;
    window["swal"]({
      title: "注意!",
      text: "是否确定删除角色",
      type: "info",
      confirmButtonText: "确认",
      confirmButtonColor: "#DD6B55",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    },
      function (isConfirm) {
        if (isConfirm) {
          that.roleControlService.delRoled(item.nRoleid).subscribe(data => {
            if (data) {
              window["swal"]("成功", "已删除该角色", "success");
              that.getRoleList();
            }
          })
        }
      })
  }

  //获取部门下所有员工
  getDeptStaffs(item) {
    let that = this;
    this.staffList = [];
    this.roleControlService.getDeptStaffs(item).subscribe(data => {
      if (data) {
        _.forEach(data, function (item, index) {
          if (item.constructor == Object) {
            that.staffList.push(item);
          }
        });
      }
    });
  }

  //查询-角色文档权限
  getDocumentAuthority() {
    let that = this;
    var nRoleid = this.roleAddOrEditInfo.nRoleid;
    this.documentAuthorityPublicList = [];
    this.documentAuthorityOtmList = [];
    this.documentAuthorityOtoList = [];
    console.log("查询-角色文档权限" + nRoleid);
    this.roleControlService.getDocumentAuthority(nRoleid).subscribe(data => {
      if (data) {
        console.log(data)
        _.forEach(data, (item, index) => {
          switch (item.labelName) {
            case "公募基金":
              that.documentAuthorityPublicLableName = item.labelName;
              that.documentAuthorityPublicList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityPublicList, 'documentPublicCheckAll')
              break;
            case "一对多专户":
              that.documentAuthorityOtmLableName = item.labelName;
              that.documentAuthorityOtmList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityOtmList, 'documentOtmCheckAll')
              break;
            case "一对一专户":
              that.documentAuthorityOtoLableName = item.labelName;
              that.documentAuthorityOtoList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityOtoList, 'documentOtoCheckAll')
              break;
            case "企业年金":
              that.documentAuthorityAnnuityLableName = item.labelName;
              that.documentAuthorityAnnuityList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityAnnuityList, 'documentAnnuityCheckAll')
              break;
            case "养老金产品":
              that.documentAuthorityOldageProLableName = item.labelName;
              that.documentAuthorityOldageProList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityOldageProList, 'documentOldageProCheckAll')
              break;
            case "社保基金":
              that.documentAuthoritySocialLableName = item.labelName;
              that.documentAuthoritySocialList = item.lableList;
              that.ctrlCheckAll(that.documentAuthoritySocialList, 'documentSocialCheckAll')
              break;
            case "养老基金":
              that.documentAuthorityOldageLableName = item.labelName;
              that.documentAuthorityOldageList = item.lableList;
              that.ctrlCheckAll(that.documentAuthorityOldageList, 'documentOldageCheckAll')
              break;
          }
        })
      }
    });
  }
  //获取ztree处理成需要post的数据
  needPostBody() {
    var treeObj = window['$'].fn.zTree.getZTreeObj("deptZtree");
    var nodes = treeObj.getCheckedNodes(false);
    var postBody = [];

    _.forEach(nodes, item => {
      if (item.users !== null) {
        _.forEach(item.users, it => {
          var postObj = {
            nRoleid: this.roleId,
            sUsername: '',
            checked: ''
          };
          postObj.sUsername = it.sUsername;
          postObj.checked = it.checked;
          postBody.push(postObj);

        });
      }
    });
    return postBody;
  }
  //添加-角色用户
  addRoleUser() {
    let that = this;
    this.addUserPost = this.needPostBody();
    var postBody = _.filter(this.addUserPost, function (n, index) {
      return n.checked != that.initializationPostInfo[index].checked;
    });
    window['swal']({
      title: "提示",
      text: "是否确定添加角色用户?",
      type: "warning",
      showCancelButton: true,
      closeOnConfirm: false,
      confirmButtonText: "确认",
      confirmButtonColor: "#DD6B55",
      cancelButtonText: "取消",
      showLoaderOnConfirm: true,
    }, function (isConfirm) {
      if (isConfirm) {
        that.roleControlService.addRoleUser(postBody).subscribe(data => {
          if (data) {
            window["swal"]("提示", "保存成功", "success");
            that.getRoleUserList();
            that.getDeptTree();
          }
        })
      }
    })
  }

  //查询该角色下所有用户信息
  getRoleUserList() {
    let that = this;
    this.roleControlService.getRoleUserList(this.roleId).subscribe(data => {
      if (data) {
        that.roleUserList = data;
      }
    });
  }
  /**
   * 重置modal
   */
  tabActive() {
    window['$']("#tab2").removeClass('active');
    window['$']("#tab_2").removeClass('active');
    window['$']("#tabTwoContent").attr('aria-expanded', "false");
    window['$']("#tab3").removeClass('active');
    window['$']("#tab_3").removeClass('active');
    window['$']("#tabThridContent").attr('aria-expanded', "false");
    window['$']("#tab4").removeClass('active');
    window['$']("#tab_4").removeClass('active');
    window['$']("#tabFourContent").attr('aria-expanded', "false");
    window['$']("#tab1").addClass('active');
    window['$']("#tab_1").addClass('active');
    window['$']("#tabOneContent").attr('aria-expanded', "true");
  }
  //删除-角色用户(单个)
  delRoleUser(sUsername, sRealname) {
    let that = this;
    this.delUserputBody.nRoleid = this.roleId;
    this.delUserputBody.sUsername = sUsername;
    window["swal"]({
      title: "注意!",
      text: "是否要删除 " + sRealname + " 用户?",
      type: "info",
      confirmButtonText: "确认",
      confirmButtonColor: "#DD6B55",
      cancelButtonText: "取消",
      showCancelButton: true,
      closeOnConfirm: false,
      closeOnCancel: true,
      showLoaderOnConfirm: true
    }, function () {
      that.roleControlService.delRoleUser(that.delUserputBody).subscribe(data => {
        if (data) {
          window["swal"]("成功", "成功删除用户", "success");
          that.getRoleUserList();
        }
      })
    });

  }
  //更新-角色菜单权限
  updateMenuAuthority() {
    let that = this;
    var menuResourceListPost = [];

    var treeObj = window['$'].fn.zTree.getZTreeObj("menuZtree");
    // console.log(treeObj);
    var nodes = treeObj.getCheckedNodes(true);
    // console.log(nodes)
    var checkedMenuButtonList = []; 
    
    _.forEach(nodes, (item, index) => {
      if (item.resource !== null && item.resource.length > 0) {
        var menuResourceObj = {
          nRoleid: this.roleId,
          sMenuCode: '',
          sResource: ''
        };
        checkedMenuButtonItem = '';
        checkedMenuButtonList = [];
        _.forEach(item.resource, (it, idx) => {
          if (it.checked == true) {
            checkedMenuButtonList.push(it.id);
          }
        });
        console.log(checkedMenuButtonList);
        var checkedMenuButtonItem = checkedMenuButtonList.join(',');
        menuResourceObj.sResource = checkedMenuButtonItem;
        menuResourceObj.sMenuCode = item.data;
        menuResourceListPost.push(menuResourceObj);
      } else {
        var menuResourceObj = {
          nRoleid: this.roleId,
          sMenuCode: '',
          sResource: ''
        };
        checkedMenuButtonItem = '';
        checkedMenuButtonList = [];

        menuResourceObj.sResource = '';
        menuResourceObj.sMenuCode = item.data;
        menuResourceListPost.push(menuResourceObj);
      }
    });
    window['swal']({
      title: "提示",
      text: "是否确定更新角色菜单权限?",
      type: "warning",
      showCancelButton: true,
      closeOnConfirm: false,
      confirmButtonText: "确认",
      confirmButtonColor: "#DD6B55",
      cancelButtonText: "取消",
      showLoaderOnConfirm: true,
    }, function (isConfirm) {
      if (isConfirm) {
        // console.log(menuResourceListPost);
        // console.log(that.roleId);
        that.roleControlService.updateMenuAuthority(menuResourceListPost, that.roleId).subscribe(data => {
          if (data) {
            console.log(data);
            window["swal"]("成功", "更新菜单权限成功", "success");
          }
        })
      }
    })
  }
  //查询-角色数据权限标签
  getDataAuthority() {
    let that = this;
    var nRoleid = this.roleAddOrEditInfo.nRoleid;
    if(this.dataAuthorityList.length == 0){
      this.roleControlService.getDataAuthority(nRoleid).subscribe(data => {
        if (data) {
          this.dataAuthorityList = data[0].labelList;
          this.ctrlCheckAll(this.dataAuthorityList, 'fundTypeCheckAll');
          this.fundCodeCheckedList = data[1].labelList;
          _.forEach(this.fundCodeCheckedList, function (item) {
            that.fundSelectedCodeList.push(item.id);
          });
          this.getListRoleDataFundCodePage();
        }
      });
    }
    
  }
  //获取select2中的数据进行处理
  getSelect2CodeList() {
    let codeList = [];
    var list = window['$']('.fields-select').val();
    _.forEach(list, item => {
      var index1 = item.indexOf("'");
      var index2 = item.lastIndexOf("'");
      var code = item.substring(index1 + 1, index2);
      codeList.push(code);
    });
    return codeList;
  }
  //更新-角色数据权限
  updateInfoAuthority(authorityType) {
    let that = this;
    this.roleDataPutBody.nRoleid = this.roleId;
    var checkedTypeItem = [];
    var checkedCodeItem = this.getSelect2CodeList();
    var checkedWordItemList = [];
    _.forEach(this.dataAuthorityList, function (item, index) {
      if (item.checked == true) {
        checkedTypeItem.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityPublicList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityOtmList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityOtoList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityAnnuityList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityOldageList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthorityOldageProList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    _.forEach(this.documentAuthoritySocialList, function (item, index) {
      if (item.checked == true) {
        checkedWordItemList.push(item.id);
      }
    });
    let converTypeItem = checkedTypeItem.join(',');
    let converCodeItem = checkedCodeItem.join(',');
    let converWordItemList = checkedWordItemList.join(',');
    if (authorityType == '数据权限') {
      this.roleDataPutBody.sFundtypeSet = converTypeItem;
      this.roleDataPutBody.sFundcodes = converCodeItem;
      this.roleDataPutBody.sAttachSet = null;
    } else if (authorityType == '文档权限') {
      this.roleDataPutBody.sFundtypeSet = null;
      this.roleDataPutBody.sFundcodes = null;
      this.roleDataPutBody.sAttachSet = converWordItemList;
    }
    window['swal']({
      title: "提示",
      text: "是否确定更新角色" + authorityType + "?",
      type: "warning",
      showCancelButton: true,
      closeOnConfirm: false,
      confirmButtonText: "确认",
      confirmButtonColor: "#DD6B55",
      cancelButtonText: "取消",
      showLoaderOnConfirm: true,
    }, function (isConfirm) {
      if (isConfirm) {
        that.roleControlService.updateInfoAuthority(that.roleDataPutBody).subscribe(data => {
          if (data) {
            window["swal"]("成功", "更新" + authorityType + "成功", "success");
          }
        })
      }
    })
  }
  //查询-用户的产品代码列表（分页）
  getListRoleDataFundCodePage() {
    if(this.fundCodeList.length == 0){
      this.roleControlService.getListRoleDataFundCodePage(this.getListRoleDataFundCodePagePost).subscribe(data => {
        if (data) {
          this.fundCodeList = data.list;
        }
      });
    }
   
  }
  //查询-所有部门信息
  getAlldept() {
    this.roleControlService.getAlldept().subscribe(data => {
      if (data) {
        this.deptList = data;
      }
    });
  }
  // 点击表格头排序
  orderData(colName) {
    let listDataAsc = _.orderBy(this.roleList, [colName], ["asc"]);
    if (JSON.stringify(this.roleList) == JSON.stringify(listDataAsc)) {
      listDataAsc = _.orderBy(this.roleList, [colName], ["desc"]);
    }
    this.roleList = listDataAsc;
  }
}

